#delimit ;
set more off;
pause on;
clear;

/*****************************************************************************/
/* ABOUT THIS FILE */
/*****************************************************************************/

/*
OVERVIEW
The purpose of this file is to code the posters for appeals.

General approach to naming variables
  1. First part:  part of the poster it comes from (c = clothing, i=imagery, t=text). 1 or 2 are used after to refer to candidate 1 or 2.
  2. Second part: the broad category (rel=religion, eth=ethnicity)
  3. Third part:  specific religion (is=Islam, ch=Christian) or ethnicity. (Ethnic groups are spelled out in full)
  4. Fourth part: whether it is a binary or a continous variable.

CONTENTS
PART 1. CODING
  1. Initial setup
  2. Clothing
  3. Images
  4. Text
    Note: I create continuous and binary variables for the codes. For instance a code for the number of Islamic articles of clothing worn by the head and deputy candidates in the poster, as well as a binary variable for whether any Islamic clothing is used. Only the binary variables are however used in the manuscript.

PART 2. TYPES OF APPEALS
  1. Initial setup
  2. Any appeals to religion, any appeals to ethnicity
  3. Single-categorization: an appeal to a single category
  4. Re-categorization: an appeal to the general category, not specific to a group e.g. religiosity
  5. Cross-categorization: an appeal to multiple categories
    Note: I do not consider the identity of the candidates so I can not say if the appeals are bonding or bridging. Instead I code for a poster that appeals to a single ethnic group (single-categorization); an ethnic dimension (re-categorization); or to multiple ethnic categories (cross-categorization). In db.do file I consider the identity of candidates and code posters as bonding or bridging.

PART 3. ID VARS
  1. ID Vars
  2. Keep and save
*/

/******************************************************************************/
/******************************************************************************/
                            /* PART 1 CODING */
/******************************************************************************/
/******************************************************************************/


/******************************************************************************/
/* 1. INITIAL SETUP */
/******************************************************************************/

insheet  using "csv/appeals.csv";

/* Ethnic group macro --------------------------------------------------------*/
/* This creates a macro so later when I loop through every ethnic group I just
use ethgrp_fullset. Banjar, Madurese and Minahasa only appear in languages.*/

local ethgrp_fullset
acehnese ambon bajawa banjar balinese betawi bugis chinese javanese karo lampung
luwu madurese makassar malay manggarai minahasa minangkabau nagekeo ngada nias
papua sekadau simalungun sumba sundanese toba toraja;

/* Lower case ----------------------------------------------------------------*/
replace verbal_appeals=lower(verbal_appeals);

/* Cut punctuation -----------------------------------------------------------*/
replace verbal_appeals = subinstr(verbal_appeals, "'", "",.);
replace verbal_appeals = subinstr(verbal_appeals, "!", "",.);
replace verbal_appeals = subinstr(verbal_appeals, ".", " . ",.);
replace verbal_appeals = subinstr(verbal_appeals, "-", " - ",.);
replace verbal_appeals = subinstr(verbal_appeals, "?", " ? ",.);
replace verbal_appeals = subinstr(verbal_appeals, ",", " , ",.);
replace verbal_appeals = subinstr(verbal_appeals, ":", " : ",.);
replace verbal_appeals = subinstr(verbal_appeals, ";", " ; ",.);
replace verbal_appeals = subinstr(verbal_appeals, "(", "( ",.);
replace verbal_appeals = subinstr(verbal_appeals, ")", " )",.);

/******************************************************************************/
/* 2. CLOTHING */
/******************************************************************************/

/* RELIGIOUS CLOTHING --------------------------------------------------------*/
/* Only Islamic and Christian clothing is used and coded in the posters.
Continous vars are made for Christian clothing, but only Priest clothing
exists, so it is redundant */

/* Islam ---------------------------------------------------------------------*/
gen c1_rel_is_c = 0;
gen c1_rel_is_b = 0;
replace c1_rel_is_c = c1_rel_is_c + 1 if hd1 == "jilbab large";
replace c1_rel_is_c = c1_rel_is_c + 1 if hd1 == "jilbab reg";
replace c1_rel_is_c = c1_rel_is_c + 1 if hd1 == "selenda";
replace c1_rel_is_c = c1_rel_is_c + 1 if hd1 == "peci design islamic";
replace c1_rel_is_c = c1_rel_is_c + 1 if hd1 == "skullcap";
replace c1_rel_is_c = c1_rel_is_c + 1 if hd1 == "turban";
replace c1_rel_is_c = c1_rel_is_c + 1 if clothing1 == "islamic";
replace c1_rel_is_c = c1_rel_is_c + 1 if cloth_acc1 == "islamic";
replace c1_rel_is_b = 1 if c1_rel_is_c> = 1;

gen c2_rel_is_c = 0;
gen c2_rel_is_b = 0;
replace c2_rel_is_c = c2_rel_is_c + 1 if hd2 == "jilbab large";
replace c2_rel_is_c = c2_rel_is_c + 1 if hd2 == "jilbab reg";
replace c2_rel_is_c = c2_rel_is_c + 1 if hd2 == "selenda";
replace c2_rel_is_c = c2_rel_is_c + 1 if hd2 == "peci design islamic";
replace c2_rel_is_c = c2_rel_is_c + 1 if hd2 == "skullcap";
replace c2_rel_is_c = c2_rel_is_c + 1 if hd2 == "turban";
replace c2_rel_is_c = c2_rel_is_c + 1 if clothing2 == "islamic";
replace c2_rel_is_c = c2_rel_is_c + 1 if cloth_acc2 == "islamic";
replace c2_rel_is_b = 1 if c2_rel_is_c> = 1;

gen c_rel_is_c = c1_rel_is_c + c2_rel_is_c;
gen c_rel_is_b = 1;
replace c_rel_is_b = 0 if c_rel_is_c == 0;

/* Christian -----------------------------------------------------------------*/
gen c1_rel_ch_c = 0;
gen c1_rel_ch_b = 0;
replace c1_rel_ch_c = c1_rel_ch_c + 1 if clothing1 == "priest";
replace c1_rel_ch_b = 1 if c1_rel_ch_c> = 1;

gen c2_rel_ch_c = 0;
gen c2_rel_ch_b = 0;
replace c2_rel_ch_c = c2_rel_ch_c + 1 if clothing2 == "priest";
replace c2_rel_ch_b = 1 if c2_rel_ch_c> = 1;

gen c_rel_ch_c = c1_rel_ch_c + c2_rel_ch_c;
gen c_rel_ch_b = 1;
replace c_rel_ch_b = 0 if c_rel_ch_c == 0;

/* ETHNIC CLOTHING --------------------------------------------------------*/

/* Generates a general ethnic clothing category for candidates wearing Modern
Batik. This batik is not specific to an ethnic group, but it is distinctively Indonesian.
c1_eth_gen_b =  1 if candidate 1 is wearing modern batik.
c2_eth_gen_b =  1 if candidate 2 is wearing modern batik.
c_eth_gen_c =   0 if no candidate is wearing it;
                1 if one candidate is wearing it;
                2 if two candidates are wearing it.
c_eth_gen_b =   1 is any candidate is wearing it */

gen c1_eth_gen_b = 0;
replace c1_eth_gen_b = 1 if clothing1 == "batik modern";
gen c2_eth_gen_b = 0;
replace c2_eth_gen_b = 1 if clothing2 == "batik modern";
gen c_eth_gen_c = c1_eth_gen_b + c2_eth_gen_b;
gen c_eth_gen_b = 1;
replace c_eth_gen_b = 0 if c_eth_gen_c == 0;

/* Generates ethnic clothing for each ethnic group */
/* 'foreach' to loop through, and create variables for each ethnic group.
Continous var ranges from 0-3. 3 has clothing, scarf, and headdress from ethnic grp. Binary var is 1 or more for each candidate(s) for every ethnic group. In the final line a var for c_eth_b (any specific ethnic group clothing) is made.*/

gen c_eth_b = 0;

foreach ethgrp in `ethgrp_fullset'{;
gen c1_eth_`ethgrp'_c = 0;
replace c1_eth_`ethgrp'_c = c1_eth_`ethgrp'_c + 1 if clothing1 == "ethnic `ethgrp'";
replace c1_eth_`ethgrp'_c = c1_eth_`ethgrp'_c + 1 if cloth_acc1 == "ethnic `ethgrp'";
replace c1_eth_`ethgrp'_c = c1_eth_`ethgrp'_c + 1 if hd1 == "ethnic `ethgrp'";

gen c1_eth_`ethgrp'_b = 0;
replace c1_eth_`ethgrp'_b = 1 if c1_eth_`ethgrp'_c> = 1;

gen c2_eth_`ethgrp'_c = 0;
replace c2_eth_`ethgrp'_c = c2_eth_`ethgrp'_c + 1 if clothing2 == "ethnic `ethgrp'";
replace c2_eth_`ethgrp'_c = c2_eth_`ethgrp'_c + 1 if cloth_acc2 == "ethnic `ethgrp'";
replace c2_eth_`ethgrp'_c = c2_eth_`ethgrp'_c + 1 if hd2 == "ethnic `ethgrp'";

gen c2_eth_`ethgrp'_b = 0;
replace c2_eth_`ethgrp'_b = 1 if c2_eth_`ethgrp'_c> = 1;

gen c_eth_`ethgrp'_c = c1_eth_`ethgrp'_c + c2_eth_`ethgrp'_c;

gen c_eth_`ethgrp'_b = 1;
replace c_eth_`ethgrp'_b = 0 if c_eth_`ethgrp'_c == 0;

replace c_eth_b = 1 if c_eth_`ethgrp'_b == 1;
};

/******************************************************************************/
/* 3. IMAGES */
/******************************************************************************/

/* RELIGIOUS IMAGES ----------------------------------------------------------*/

/* Islam*/
gen i_rel_is_c = 0;
gen i_rel_is_b = 0;

replace i_rel_is_c=i_rel_is_c + 1 if (regexm(imagery, "islam"));
replace i_rel_is_c=i_rel_is_c + 1 if (regexm(imagery, "islamic"));
replace i_rel_is_c=i_rel_is_c + 1 if (regexm(imagery, "mecca"));
replace i_rel_is_c=i_rel_is_c + 1 if (regexm(imagery, "mosque"));
replace i_rel_is_c=i_rel_is_c + 1 if (regexm(elites, "religion-islam"));
replace i_rel_is_c=i_rel_is_c + 1 if (regexm(supporter_id, "religious-islam"));
replace i_rel_is_b = 1 if i_rel_is_c> = 1;

/* Christian */
gen i_rel_ch_c = 0;
gen i_rel_ch_b = 0;
replace i_rel_ch_c=i_rel_ch_c + 1 if (regexm(imagery, "church"));
replace i_rel_ch_c=i_rel_ch_c + 1 if (regexm(imagery, "christian"));
replace i_rel_is_c=i_rel_is_c + 1 if (regexm(elites, "religion-christian"));
replace i_rel_is_c=i_rel_is_c + 1 if (regexm(supporter_id, "religious-christian"));
replace i_rel_ch_b = 1 if i_rel_ch_c> = 1;

/* Hindu */
gen i_rel_hi_c = 0;
gen i_rel_hi_b = 0;
replace i_rel_hi_c=i_rel_hi_c + 1 if (regexm(imagery, "hindu"));
replace i_rel_is_c=i_rel_is_c + 1 if (regexm(elites, "religion-hindu"));
replace i_rel_hi_b = 1 if i_rel_hi_c> = 1;

/* Buddhist */
gen i_rel_bu_c = 0;
gen i_rel_bu_b = 0;
replace i_rel_bu_c=i_rel_bu_c + 1 if (regexm(imagery, "vihara"));
replace i_rel_is_c=i_rel_is_c + 1 if (regexm(elites, "religion-buddhist"));
replace i_rel_bu_b = 1 if i_rel_bu_c> = 1;

/* ETHNIC IMAGES -------------------------------------------------------------*/

foreach ethgrp in `ethgrp_fullset'{;
gen i_eth_`ethgrp'_c = 0;
replace i_eth_`ethgrp'_c=i_eth_`ethgrp'_c + 1 if (regexm(imagery, "`ethgrp'"));
replace i_eth_`ethgrp'_c=i_eth_`ethgrp'_c + 1 if (regexm(elites, "ethnic-`ethgrp'"));
replace i_eth_`ethgrp'_c=i_eth_`ethgrp'_c + 1 if (regexm(supporter_id, "ethnic-`ethgrp'"));
gen i_eth_`ethgrp'_b = 0;
replace i_eth_`ethgrp'_b = 1 if i_eth_`ethgrp'_c> = 1;
};

/* POLITICAL PARTY ELITES ----------------------------------------------------*/
gen party_elites = 0;
replace party_elites = 1 if (regexm(elites, "political-party"));

/******************************************************************************/
/* 4. TEXT */
/******************************************************************************/

/* RELIGION TEXT -------------------------------------------------------------*/

/* Religion General */
local religion_gen
religius
religis
tuhan
doa
agama
ibadah
jiwa
agamis
amin
beragama
beriman
kepercayaan
rohani
sakril
suci
toleransi
tolerans
toleran
keragaman
pluralisme
berdoa;

gen t_rel_c = 0;
gen t_rel_b = 0;
foreach keyword in `religion_gen'{;
replace t_rel_c = t_rel_c + 1 if (regexm(verbal_appeals, " `keyword' "));
replace t_rel_c = t_rel_c + 1 if (regexm(verbal_appeals, "^`keyword' "));
replace t_rel_c = t_rel_c + 1 if (regexm(verbal_appeals, " `keyword'$"));
replace t_rel_c = t_rel_c + 1 if (regexm(verbal_appeals, "^`keyword'$"));
};

replace t_rel_c = t_rel_c +1 if (regexm(verbal_appeals, "umat beragama"));
replace t_rel_c = t_rel_c +1 if (regexm(verbal_appeals, "agama harmonis"));
replace t_rel_b = 1 if t_rel_c> = 1;

tab t_rel_b t_rel_c if t_rel_c> = 1;

/* Religion Islam */
local religion_islam
islam
allah
masjid
mesjid
ahhal
muslimah
muslimat
kabah
kaba
shariah
syaria
syariat
akbar
hadith
ustadz
assalamu
alhamdullilah
allahuakbar
alwasliyah
arabic
haji
syawal
imam
insyaallah
insyalloh
kyai
muhammadiya
muharam
muharram
muslim
muslimin
persis
qur'an
sholat
shalat
shaleh
shariat
shariah
syekh
taqwa
ulama
ustadz
ramadhan
;

gen t_rel_is_c = 0;
gen t_rel_is_b = 0;
foreach keyword in `religion_islam'{;
replace t_rel_is_c = t_rel_is_c + 1 if (regexm(verbal_appeals, " `keyword' "));
replace t_rel_is_c = t_rel_is_c + 1 if (regexm(verbal_appeals, "^`keyword' "));
replace t_rel_is_c = t_rel_is_c + 1 if (regexm(verbal_appeals, " `keyword'$"));
replace t_rel_is_c = t_rel_is_c + 1 if (regexm(verbal_appeals, "^`keyword'$"));
};
replace t_rel_is_c = t_rel_is_c +1 if (regexm(verbal_appeals, "idul fitri"));
replace t_rel_is_c = t_rel_is_c +1 if (regexm(verbal_appeals, "babi ilegal"));
replace t_rel_is_c = t_rel_is_c +1 if (regexm(foreign_lang, "arabic"));
replace t_rel_is_b = 1 if t_rel_is_c> = 1;
tab t_rel_is_b t_rel_is_c if t_rel_is_c> = 1;

/* Religion Christian */
local religion_christian
gbkp
gereja
katolik
kristen
kristus
mazmur
protestan
paskah
natal
masehi
Yesus
;

gen t_rel_ch_c = 0;
gen t_rel_ch_b = 0;
foreach keyword in `religion_christian'{;
replace t_rel_ch_c = t_rel_ch_c + 1 if (regexm(verbal_appeals, " `keyword' "));
replace t_rel_ch_c = t_rel_ch_c + 1 if (regexm(verbal_appeals, "^`keyword' "));
replace t_rel_ch_c = t_rel_ch_c + 1 if (regexm(verbal_appeals, " `keyword'$"));
replace t_rel_ch_c = t_rel_ch_c + 1 if (regexm(verbal_appeals, "^`keyword'$"));
};
replace t_rel_is_c = t_rel_is_c +1 if (regexm(foreign_lang, "latin"));
replace t_rel_is_c = t_rel_is_c +1 if (regexm(foreign_lang, "hebrew"));

replace t_rel_ch_b = 1 if t_rel_ch_c> = 1;
tab t_rel_ch_b t_rel_ch_c if t_rel_ch_c> = 1;

/* ETHNIC TEXT ---------------------------------------------------------------*/

/* Ethnic General */
local ethnic_gen
suku
budaya
berbudaya
ras
adat
etnis
beradat
native;

gen t_eth_c = 0;
gen t_eth_b = 0;
foreach keyword in `ethnic_gen'{;
replace t_eth_c = t_eth_c + 1 if (regexm(verbal_appeals, " `keyword' "));
replace t_eth_c = t_eth_c + 1 if (regexm(verbal_appeals, "^`keyword' "));
replace t_eth_c = t_eth_c + 1 if (regexm(verbal_appeals, " `keyword'$"));
replace t_eth_c = t_eth_c + 1 if (regexm(verbal_appeals, "^`keyword'$"));
};
replace t_eth_c = t_eth_c +1 if (regexm(verbal_appeals, "kain tradisional"));
replace t_eth_b = 1 if t_eth_c> = 1;

tab t_eth_b t_eth_c if t_eth_c> = 1;

/* Ethnic Languages */
replace foreign_lang = "ambon" if foreign_lang == "ambon-malay";
replace foreign_lang = "sumba" if foreign_lang == "sumba-wewewa"; // late correction (R1)

foreach ethgrp in `ethgrp_fullset'{;
gen t_eth_`ethgrp'_c = 0;
replace t_eth_`ethgrp'_c = t_eth_`ethgrp'_c + 1 if (regexm(foreign_lang, "`ethgrp'"));
gen t_eth_`ethgrp'_b = 0;
replace t_eth_`ethgrp'_b = 1 if t_eth_`ethgrp'_c> = 1;
};

/******************************************************************************/
/******************************************************************************/
                      /* PART 2 TYPES OF APPEALS */
/******************************************************************************/
/******************************************************************************/

/******************************************************************************/
/* 1. INITIAL SETUP */
/******************************************************************************/

/* These macros are used to exclude ethnic groups in checking for single
categorization (appeals to a single ethnic group) */

local ethgrp_eacehnese
 ambon banjar balinese betawi bugis chinese javanese karo lampung luwu madurese
 makassar malay manggarai minahasa minangkabau ngada nias papua sekadau
 simalungun sumba sundanese toba toraja nagekeo bajawa;

local ethgrp_eambon
acehnese  banjar balinese betawi bugis chinese javanese karo lampung luwu madurese
makassar malay manggarai minahasa minangkabau ngada nias papua sekadau
simalungun sumba sundanese toba toraja nagekeo bajawa;

local ethgrp_ebanjar
acehnese ambon  balinese betawi bugis chinese javanese karo lampung luwu madurese
makassar malay manggarai minahasa minangkabau ngada nias papua sekadau
simalungun sumba sundanese toba toraja nagekeo bajawa;

local ethgrp_ebalinese
acehnese ambon banjar  betawi bugis chinese javanese karo lampung luwu madurese
makassar malay manggarai minahasa minangkabau ngada nias papua sekadau
simalungun sumba sundanese toba toraja nagekeo bajawa;

local ethgrp_ebetawi
acehnese ambon banjar balinese  bugis chinese javanese karo lampung luwu madurese
makassar malay manggarai minahasa minangkabau ngada nias papua sekadau
simalungun sumba sundanese toba toraja nagekeo bajawa;

local ethgrp_ebugis
acehnese ambon banjar balinese betawi  chinese javanese karo lampung luwu madurese
makassar malay manggarai minahasa minangkabau ngada nias papua sekadau
simalungun sumba sundanese toba toraja nagekeo bajawa;

local ethgrp_echinese
acehnese ambon banjar balinese betawi bugis  javanese karo lampung luwu madurese
makassar malay manggarai minahasa minangkabau ngada nias papua sekadau
simalungun sumba sundanese toba toraja nagekeo bajawa;

local ethgrp_ejavanese
acehnese ambon banjar balinese betawi bugis chinese  karo lampung luwu madurese
makassar malay manggarai minahasa minangkabau ngada nias papua sekadau
simalungun sumba sundanese toba toraja nagekeo bajawa;

local ethgrp_ekaro
acehnese ambon banjar balinese betawi bugis chinese javanese lampung luwu madurese
makassar malay manggarai minahasa minangkabau ngada nias papua sekadau
simalungun sumba sundanese toba toraja nagekeo bajawa;

local ethgrp_elampung
acehnese ambon banjar balinese betawi bugis chinese javanese karo luwu madurese
makassar malay manggarai minahasa minangkabau ngada nias papua sekadau
simalungun sumba sundanese toba toraja nagekeo bajawa;

local ethgrp_eluwu
acehnese ambon banjar balinese betawi bugis chinese javanese karo lampung
madurese makassar malay manggarai minahasa minangkabau ngada nias papua sekadau
simalungun sumba sundanese toba toraja nagekeo bajawa;

local ethgrp_emadurese
acehnese ambon banjar balinese betawi bugis chinese javanese karo lampung
luwu makassar malay manggarai minahasa minangkabau ngada nias papua sekadau
simalungun sumba sundanese toba toraja nagekeo bajawa;

local ethgrp_emakassar
acehnese ambon banjar balinese betawi bugis chinese javanese karo lampung
luwu madurese  malay manggarai minahasa minangkabau ngada nias papua sekadau
simalungun sumba sundanese toba toraja nagekeo bajawa;

local ethgrp_emalay
acehnese ambon banjar balinese betawi bugis chinese javanese karo lampung
luwu madurese makassar  manggarai minahasa minangkabau ngada nias papua sekadau
simalungun sumba sundanese toba toraja nagekeo bajawa;

local ethgrp_emanggarai
acehnese ambon banjar balinese betawi bugis chinese javanese karo lampung
luwu madurese makassar malay  minahasa minangkabau ngada nias papua sekadau
simalungun sumba sundanese toba toraja nagekeo bajawa;

local ethgrp_eminahasa
acehnese ambon banjar balinese betawi bugis chinese javanese karo lampung
luwu madurese makassar malay manggarai  minangkabau ngada nias papua sekadau
simalungun sumba sundanese toba toraja nagekeo bajawa;

local ethgrp_eminangkabau
acehnese ambon banjar balinese betawi bugis chinese javanese karo lampung
luwu madurese makassar malay manggarai minahasa ngada nias papua sekadau
simalungun sumba sundanese toba toraja nagekeo bajawa;

local ethgrp_engada
acehnese ambon banjar balinese betawi bugis chinese javanese karo lampung
luwu madurese makassar malay manggarai minahasa minangkabau  nias papua sekadau
simalungun sumba sundanese toba toraja nagekeo bajawa;

local ethgrp_enias
acehnese ambon banjar balinese betawi bugis chinese javanese karo lampung
luwu madurese makassar malay manggarai minahasa minangkabau ngada papua sekadau
simalungun sumba sundanese toba toraja nagekeo bajawa;

local ethgrp_epapua
acehnese ambon banjar balinese betawi bugis chinese javanese karo lampung
luwu madurese makassar malay manggarai minahasa minangkabau ngada nias  sekadau
simalungun sumba sundanese toba toraja nagekeo bajawa;

local ethgrp_esekadau
acehnese ambon banjar balinese betawi bugis chinese javanese karo lampung
luwu madurese makassar malay manggarai minahasa minangkabau ngada nias papua
simalungun sumba sundanese toba toraja nagekeo bajawa;

local ethgrp_esimalungun
acehnese ambon banjar balinese betawi bugis chinese javanese karo lampung
luwu madurese makassar malay manggarai minahasa minangkabau ngada nias papua
sekadau sumba sundanese toba toraja nagekeo bajawa;

local ethgrp_esumba
acehnese ambon banjar balinese betawi bugis chinese javanese karo lampung
luwu madurese makassar malay manggarai minahasa minangkabau ngada nias papua
sekadau simalungun sundanese toba toraja nagekeo bajawa;

local ethgrp_esundanese
acehnese ambon banjar balinese betawi bugis chinese javanese karo lampung
luwu madurese makassar malay manggarai minahasa minangkabau ngada nias papua
sekadau simalungun sumba  toba toraja nagekeo bajawa;

local ethgrp_etoba
acehnese ambon banjar balinese betawi bugis chinese javanese karo lampung
luwu madurese makassar malay manggarai minahasa minangkabau ngada nias papua
sekadau simalungun sumba sundanese toraja nagekeo bajawa;

local ethgrp_etoraja
acehnese ambon banjar balinese betawi bugis chinese javanese karo lampung
luwu madurese makassar malay manggarai minahasa minangkabau ngada nias papua
sekadau simalungun sumba sundanese toba nagekeo bajawa;

local ethgrp_enagekeo
acehnese ambon banjar balinese betawi bugis chinese javanese karo lampung
luwu madurese makassar malay manggarai minahasa minangkabau ngada nias papua
sekadau simalungun sumba sundanese toba toraja bajawa;

local ethgrp_ebajawa
acehnese ambon banjar balinese betawi bugis chinese javanese karo lampung
luwu madurese makassar malay manggarai minahasa minangkabau ngada nias papua
sekadau simalungun sumba sundanese toba toraja nagekeo;

/******************************************************************************/
/* 2. ANY APPEALS */
/******************************************************************************/

/* ANY RELIGIOUS APPEALS -----------------------------------------------------*/
/* Any Religious Clothing */
gen c_rel_any_c = 0;
gen c_rel_any_b = 0;
replace c_rel_any_c = c_rel_is_c + c_rel_ch_c;
replace c_rel_any_b = 1 if c_rel_any_c! = 0;

/* Any Religious Images */
gen i_rel_any_c = 0;
gen i_rel_any_b = 0;
replace i_rel_any_c=i_rel_is_c + i_rel_ch_c + i_rel_hi_c + i_rel_bu_c;
replace i_rel_any_b = 1 if i_rel_any_c! = 0;

/* Any Religious Text */
gen t_rel_any_c = 0;
gen t_rel_any_b = 0;
replace t_rel_any_c= t_rel_c + t_rel_is_c + t_rel_ch_c; // Incl. general rel
replace t_rel_any_b = 1 if t_rel_any_c! = 0;

/* Any Religious Appeal (any)
any = any appeal.
any_rel_b = a poster with at least 1 religious appeal, can be general, specific or both.
any_rel_is_b = a poster with at least 1 islamic appeal, can have other religious group appeals */

/* Any Religious Appeal */
gen any_rel_c = 0;
gen any_rel_b = 0;
gen any_rel_o=0;
replace any_rel_c= c_rel_any_c + i_rel_any_c + t_rel_any_c;
replace any_rel_o= c_rel_any_b + i_rel_any_b + t_rel_any_b;
replace any_rel_b = 1 if any_rel_c! = 0;

/* Any Islamic Appeal */
gen any_rel_is_c = 0;
gen any_rel_is_b = 0;
replace any_rel_is_c = c_rel_is_c + i_rel_is_c + t_rel_is_c;
replace any_rel_is_b = 1 if any_rel_is_c! = 0;

/* Any Christian Appeal */
gen any_rel_ch_c = 0;
gen any_rel_ch_b = 0;
replace any_rel_ch_c = c_rel_ch_c + i_rel_ch_c + t_rel_ch_c;
replace any_rel_ch_b = 1 if any_rel_ch_c! = 0;

/* Any Hindu Appeal */
gen any_rel_hi_c = 0;
gen any_rel_hi_b = 0;
replace any_rel_hi_c=i_rel_hi_c;
replace any_rel_hi_b = 1 if any_rel_hi_c! = 0;

/* Any Buddhist Appeal */
gen any_rel_bu_c = 0;
gen any_rel_bu_b = 0;
replace any_rel_bu_c=i_rel_bu_c;
replace any_rel_bu_b = 1 if any_rel_bu_c! = 0;

/* ANY ETHNIC APPEALS --------------------------------------------------------*/

/* Any Ethnic Clothing */
gen c_eth_any_c = 0;
gen c_eth_any_b = 0;
replace c_eth_any_c = c_eth_gen_c;
foreach ethgrp in `ethgrp_fullset'{;
replace c_eth_any_c = c_eth_any_c + c_eth_`ethgrp'_c;
};
replace c_eth_any_b = 1 if c_eth_any_c! = 0;

/* Any Ethnic Images */
gen i_eth_any_c = 0;
gen i_eth_any_b = 0;
foreach ethgrp in `ethgrp_fullset'{;
replace i_eth_any_c=i_eth_any_c + i_eth_`ethgrp'_c;
};
replace i_eth_any_b = 1 if i_eth_any_c! = 0;

/* Any Ethnic Text */
/* General ethnic text appeals and use of ethnic languages used as measures. */
gen t_eth_any_c = 0;
gen t_eth_any_b = 0;
foreach ethgrp in `ethgrp_fullset'{;
replace t_eth_any_c = t_eth_any_c + t_eth_`ethgrp'_c;
};
replace t_eth_any_c = t_eth_any_c + t_eth_c;
replace t_eth_any_b = 1 if t_eth_any_c! = 0;
tab t_eth_any_b;

/* Any Ethnic Appeal (any)
any = any appeal.
any_eth_b is a poster that has at least 1 ethnic appeal, it can be general or specific or a combination.
any_eth_javanese_b is a poster that has at least one javanese appeal, it can have other ethnic group appeals */

/* Any Ethnic Appeal */
gen any_eth_c = 0;
gen any_eth_b = 0;
gen any_eth_o=0;
replace any_eth_c= c_eth_any_c + i_eth_any_c + t_eth_any_c;
replace any_eth_o= c_eth_any_b + i_eth_any_b + t_eth_any_b;
replace any_eth_b = 1 if any_eth_c! = 0;
tab any_eth_b;

/* Any 'Specific Ethnic Group' Appeal */
foreach ethgrp in `ethgrp_fullset'{;
gen any_eth_`ethgrp'_c = 0;
gen any_eth_`ethgrp'_b = 0;
replace any_eth_`ethgrp'_c = c_eth_`ethgrp'_c + i_eth_`ethgrp'_c + t_eth_`ethgrp'_c;
replace any_eth_`ethgrp'_b = 1 if any_eth_`ethgrp'_c! = 0;
};

/******************************************************************************/
/* 3. SINGLE CATEGORIZATION APPEALS (SA) (Appeals to one group) */
/******************************************************************************/

/* A poster that appeals to one religion. Note:
1. it can include general religious textual references too
2. it can not have appeals to other religious groups. */

/* APPEALS TO A RELIGIOUS GROUP ----------------------------------------------*/
/* Islamic Single Cat. Appeal (sa) */
gen sa_rel_is_b = any_rel_is_b;
replace sa_rel_is_b = 0 if any_rel_ch_b == 1 | any_rel_hi_b == 1 | any_rel_bu_b == 1;

/* Christian Single Cat. Appeal (sa) */
gen sa_rel_ch_b = any_rel_ch_b;
replace sa_rel_ch_b = 0 if any_rel_is_b == 1 | any_rel_hi_b == 1 | any_rel_bu_b == 1;

/* Hindu Single Cat. Appeal (sa) */
gen sa_rel_hi_b = any_rel_hi_b;
replace sa_rel_hi_b = 0 if any_rel_is_b == 1 | any_rel_ch_b == 1 | any_rel_bu_b == 1;

/* Buddhist Single Cat. Appeal (sa) */
gen sa_rel_bu_b = any_rel_bu_b;
replace sa_rel_bu_b = 0 if any_rel_is_b == 1 | any_rel_ch_b == 1 | any_rel_hi_b == 1;

/* All Posters that Only use Single Categorization Religious Appeals */
gen sa_rel_b = 0;
replace sa_rel_b = 1 if sa_rel_is_b == 1;
replace sa_rel_b = 1 if sa_rel_ch_b == 1;
replace sa_rel_b = 1 if sa_rel_bu_b == 1;
replace sa_rel_b = 1 if sa_rel_hi_b == 1;

/* Create the continous var for Religious Bonding
This counts the number of bonding messages in posters that only appeal to one
religious group */

gen sa_rel_c = 0;
replace sa_rel_c = any_rel_c if sa_rel_b == 1;
gen sa_rel_o = 0;
replace sa_rel_o = c_rel_any_b + i_rel_any_b + t_rel_any_b if sa_rel_b == 1;

/* APPEALS TO AN ETHNIC GROUP ----------------------------------------------*/

foreach ethgrp in `ethgrp_fullset'{;
gen sa_eth_`ethgrp'_b = any_eth_`ethgrp'_b;
};
foreach ethgrp in `ethgrp_eacehnese'{;
replace sa_eth_acehnese_b = 0 if any_eth_`ethgrp'_b == 1;
};
foreach ethgrp in `ethgrp_eambon'{;
replace sa_eth_ambon_b = 0 if any_eth_`ethgrp'_b == 1;
};
foreach ethgrp in `ethgrp_ebanjar'{;
replace sa_eth_banjar_b = 0 if any_eth_`ethgrp'_b == 1;
};
foreach ethgrp in `ethgrp_ebalinese'{;
replace sa_eth_balinese_b = 0 if any_eth_`ethgrp'_b == 1;
};
foreach ethgrp in `ethgrp_ebetawi'{;
replace sa_eth_betawi_b = 0 if any_eth_`ethgrp'_b == 1;
};
foreach ethgrp in `ethgrp_ebugis'{;
replace sa_eth_bugis_b = 0 if any_eth_`ethgrp'_b == 1;
};
foreach ethgrp in `ethgrp_echinese'{;
replace sa_eth_chinese_b = 0 if any_eth_`ethgrp'_b == 1;
};
foreach ethgrp in `ethgrp_ejavanese'{;
replace sa_eth_javanese_b = 0 if any_eth_`ethgrp'_b == 1;
};
foreach ethgrp in `ethgrp_ekaro'{;
replace sa_eth_karo_b = 0 if any_eth_`ethgrp'_b == 1;
};
foreach ethgrp in `ethgrp_elampung'{;
replace sa_eth_lampung_b = 0 if any_eth_`ethgrp'_b == 1;
};
foreach ethgrp in `ethgrp_eluwu'{;
replace sa_eth_luwu_b = 0 if any_eth_`ethgrp'_b == 1;
};
foreach ethgrp in `ethgrp_emadurese'{;
replace sa_eth_madurese_b = 0 if any_eth_`ethgrp'_b == 1;
};
foreach ethgrp in `ethgrp_emalay'{;
replace sa_eth_malay_b = 0 if any_eth_`ethgrp'_b == 1;
};
foreach ethgrp in `ethgrp_emanggarai'{;
replace sa_eth_manggarai_b = 0 if any_eth_`ethgrp'_b == 1;
};
foreach ethgrp in `ethgrp_eminahasa'{;
replace sa_eth_minahasa_b = 0 if any_eth_`ethgrp'_b == 1;
};
foreach ethgrp in `ethgrp_eminangkabau'{;
replace sa_eth_minangkabau_b = 0 if any_eth_`ethgrp'_b == 1;
};
foreach ethgrp in `ethgrp_engada'{;
replace sa_eth_ngada_b = 0 if any_eth_`ethgrp'_b == 1;
};
foreach ethgrp in `ethgrp_enias'{;
replace sa_eth_nias_b = 0 if any_eth_`ethgrp'_b == 1;
};
foreach ethgrp in `ethgrp_epapua'{;
replace sa_eth_papua_b = 0 if any_eth_`ethgrp'_b == 1;
};
foreach ethgrp in `ethgrp_esekadau'{;
replace sa_eth_sekadau_b = 0 if any_eth_`ethgrp'_b == 1;
};
foreach ethgrp in `ethgrp_esimalungun'{;
replace sa_eth_simalungun_b = 0 if any_eth_`ethgrp'_b == 1;
};
foreach ethgrp in `ethgrp_esumba'{;
replace sa_eth_sumba_b = 0 if any_eth_`ethgrp'_b == 1;
};
foreach ethgrp in `ethgrp_esundanese'{;
replace sa_eth_sundanese_b = 0 if any_eth_`ethgrp'_b == 1;
};
foreach ethgrp in `ethgrp_etoba'{;
replace sa_eth_toba_b = 0 if any_eth_`ethgrp'_b == 1;
};
foreach ethgrp in `ethgrp_etoraja'{;
replace sa_eth_toraja_b = 0 if any_eth_`ethgrp'_b == 1;
};
foreach ethgrp in `ethgrp_enagekeo'{;
replace sa_eth_nagekeo_b = 0 if any_eth_`ethgrp'_b == 1;
};
foreach ethgrp in `ethgrp_ebajawa'{;
replace sa_eth_bajawa_b = 0 if any_eth_`ethgrp'_b == 1;
};

/* All Posters that Only use Single Categorization (sa) Ethnic Appeals */
gen sa_eth_b = 0;
foreach ethgrp in `ethgrp_fullset'{;
replace sa_eth_b = 1 if sa_eth_`ethgrp'_b == 1;
};

gen sa_eth_c = 0;
replace sa_eth_c = any_eth_c if sa_eth_b == 1;

gen sa_eth_o = 0;
replace sa_eth_o = c_eth_any_b + i_eth_any_b + t_eth_any_b if sa_eth_b == 1;

/******************************************************************************/
/* 4. RE-CATEGORIZATION (RE) (Appeals to the larger category) */
/******************************************************************************/

/* Appeals to Religiosity */
/* Appeal to general religion category, but not specific on the religious
group. This can only occur in the text. Clothing and images are specific to a
religious group */

gen re_rel_b = t_rel_b;
replace re_rel_b = 0 if any_rel_is_b == 1 | any_rel_ch_b == 1 | any_rel_hi_b == 1 | any_rel_bu_b == 1;
gen re_rel_c = 0;
replace re_rel_c = t_rel_c if re_rel_b == 1;
gen re_rel_o = 0;
replace re_rel_o = t_rel_b if re_rel_b == 1;

/* Ethnic */
/* Appeal to general ethnic category, but not specific to an ethnic group.
This can only occur in the clothing (modern batik) and text, images are specific
to an ethnic group or to a region.  */

gen re_eth_b = t_eth_b;
replace re_eth_b = 1 if c_eth_gen_b == 1;
foreach ethgrp in `ethgrp_fullset'{;
replace re_eth_b = 0 if any_eth_`ethgrp'_b == 1;
};

gen re_eth_c = 0;
replace re_eth_c = t_eth_c + c_eth_gen_c if re_eth_b == 1;
gen re_eth_o = 0;
replace re_eth_o = t_eth_b + c_eth_gen_b if re_eth_b == 1;

/******************************************************************************/
/* 5. CROSS-CATEGORIZATION (CR) (Appeals to multiple ethnic/religious groups) */
/******************************************************************************/

/* Appeal to multiple religion categories. Coding logic:
If no religious appeal, then it can't be multiple.
If no single-only religious appeal, it can't be multiple.
If no general-only religious appeal, can't be multiple. */

gen cr_rel_b = 1;
replace cr_rel_b = 0 if any_rel_b == 0;
replace cr_rel_b = 0 if sa_rel_b == 1;
replace cr_rel_b = 0 if re_rel_b == 1;
gen cr_eth_b = 1;
replace cr_eth_b = 0 if any_eth_b == 0;
replace cr_eth_b = 0 if sa_eth_b == 1;
replace cr_eth_b = 0 if re_eth_b == 1;

/******************************************************************************/
/******************************************************************************/
                        /* PART 3. ID VARS & SAVE */
/******************************************************************************/
/******************************************************************************/

/******************************************************************************/
/* 1. ID VARS */
/******************************************************************************/

/* CANDIDATE ID */
tostring can_no, replace; // candidate number (unique in the electoral district)
tostring dis_code, replace; // dis_code number (eg 6372)
tostring prov_no, replace; // province number

gen can_id = ".";
replace can_id = election + "_" + prov_no + "_" + can_no if election == "gov";
replace can_id = election + "_" + dis_code + "_" + can_no if election == "dis_head";

/* REGION ID -----------------------------------------------------------------*/
gen reg_id = ".";
replace reg_id = "pro" + "_" + prov_no if election == "gov";
replace reg_id = "kabkota" + "_" + dis_code if election == "dis_head";
destring dis_code, replace;

/* POSTER ID -----------------------------------------------------------------*/
/* A unique number to each unique designed poster:
Election _ district _ candidate _ poster number */
tostring poster_no, replace;
gen pos_id = can_id + "_1";
replace pos_id = can_id + "_" + poster_no if poster_no != ".";

destring can_no, replace;
destring prov_no, replace;

/******************************************************************************/
/* 2. KEEP & SAVE */
/******************************************************************************/

keep
pos_id can_id reg_id // ID vars
dis_code prov_no clothing1 clothing2 clothing1_party clothing2_party partysup bgpartylogo party_elites // Index vars
any_eth_b any_eth_acehnese_b any_eth_ambon_b any_eth_bajawa_b any_eth_banjar_b any_eth_balinese_b any_eth_betawi_b any_eth_bugis_b any_eth_chinese_b any_eth_javanese_b any_eth_karo_b any_eth_lampung_b any_eth_luwu_b any_eth_madurese_b any_eth_makassar_b any_eth_malay_b any_eth_manggarai_b  any_eth_minahasa_b any_eth_minangkabau_b any_eth_nagekeo_b any_eth_ngada_b  any_eth_nias_b any_eth_papua_b any_eth_sekadau_b any_eth_simalungun_b any_eth_sumba_b any_eth_sundanese_b any_eth_toba_b any_eth_toraja_b // any ethnic appeals
any_rel_b any_rel_is_b any_rel_ch_b any_rel_hi_b any_rel_bu_b // Any religious appeals
sa_eth_b sa_rel_b // Single Categorization Appeal
cr_rel_b cr_eth_b // Cross-categorization
re_rel_b re_eth_b; // Re-categorization

/* Label */
label variable any_eth_b "Any Indigenous Appeal";
label variable sa_eth_b "Indigenous Single-Cat. Appeal";
label variable re_eth_b "Re-Cat. Indigenous Appeal";
label variable cr_eth_b "Cross-Cat. Indigenous Appeal";
label variable any_rel_b "Any Religious Appeal";
label variable sa_rel_b "Religious Single-Cat. Appeal";
label variable re_rel_b "Re-Cat. Religious Appeal";
label variable cr_rel_b "Cross-Cat. Religious Appeal";

/* Order & sort */
order can_id reg_id pos_id;
sort reg;

save "dta/appeals.dta", orphans replace;

/* ---------------------------------------------------------------------------*/
/* END -----------------------------------------------------------------------*/
/* ---------------------------------------------------------------------------*/
